<?php
$callback = htmlentities($_GET['callback']);

date_default_timezone_set("Asia/ShangHai");
include("config.php");
$Connect = new PDO('mysql:host='.$db['host'].';dbname='.$db['database'], $db['user'], $db['pass']);
$Connect->query("set names 'utf8'");


$category_id = (int)$_GET['category_id'];
$page = (int)$_GET['page'];
$perpage = (int)$_GET['perpage'];
$page = $page ?$page:1;
$perpage = $perpage?$perpage:10;
	$mOffset = ($page-1) * $perpage ;
$sql = "select face_id,face_name,source,content,type from `face_resource` where `category_id` = '".$category_id."' limit ".$mOffset.",".$perpage;
$sql_total = "select count(1) as total from `face_resource` where `category_id` = '".$category_id."'";
$exec = $Connect->query($sql);
$result  = $exec->fetchAll(PDO::FETCH_ASSOC);

$exec = $Connect->query($sql_total);
$total = $exec->fetchColumn(0);
$ret = array("data"=>$result,"total"=>$total,"perpage"=>$perpage,"page"=>$page);
echo $callback."(".json_encode($ret).")";

?>